package com.igeek.oop.sys;

import com.igeek.oop.pojo.Admin;
import com.igeek.oop.pojo.Computer;
import com.igeek.oop.pojo.ElectronicDoor;
import com.igeek.oop.pojo.Person;

import java.nio.file.Watchable;

/**
 * 总系统
 */
public class ElectronicSys {

    private final ElectronicDoor door = new ElectronicDoor();

    private final Computer computer = new Computer();

    /**
     * 按门铃
     * @param person
     */
    public void ringBell(Person person){

        person.ringBell(door);

        //需要让管理员去开门
        if(!(person instanceof Admin)){

            //当前的人不是管理员，需要管理员去开门
            Admin admin = (Admin)person;
            admin.openDoor(door);

        }else{
            //当前这个人是管理员，通过录入信息开门
            putInfo(person);
        }
    }

    /**
     * 录入信息开门
     * @param person
     */
    public void putInfo(Person person){

       boolean result = person.putCheckInfo(computer);

       if(result){
           //开门
           door.setOn(true);
           System.out.println("开门成功");
       }
    }


    /**
     * 管理员新增员工信息
     * @param admin
     */
    public void insertInfo(Admin admin){
        admin.insertInfo(computer);
    }

}

class Test{

    public static void main(String[] args) {

        ElectronicSys sys = new ElectronicSys();

        sys.ringBell(new Admin());
    }
}